package com.jdbc.homework2;

import java.util.Scanner;

import static com.jdbc.homework2.PetManager.viewPets;

public class PetStoreSystem {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();

        boolean isAdmin = LoginSystem.login(username, password);
        if (isAdmin) {
            System.out.println("登录成功！欢迎管理员！");
            adminMenu(scanner);
        } else {
            System.out.println("登录成功！欢迎顾客！");
            customerMenu(scanner);
        }
    }

    private static void adminMenu(Scanner scanner) {
        while (true) {
            System.out.println("管理员菜单：\n1. 添加宠物\n2. 更新宠物\n3. 删除宠物\n4. 查看宠物\n5. 退出");
            System.out.print("请选择操作：");
            int choice = scanner.nextInt();
            scanner.nextLine(); // 清除缓冲区

            switch (choice) {
                case 1:
                    System.out.println("添加宠物");
                    // 调用添加宠物的方法
                    Scanner scanner1 = new Scanner(System.in);
                    System.out.println("请输入宠物的昵称：");
                    String nickname = scanner1.nextLine();
                    System.out.println("请输入宠物的类型：");
                    String type = scanner1.nextLine();
                    System.out.println("请输入宠物的年龄：");
                    int age = scanner1.nextInt();
                    System.out.println("请输入宠物的性别：");
                    String gender = scanner1.nextLine();
                    PetManager.addPet(nickname, type, age, gender);
                    break;
                case 2:
                    System.out.println("更新宠物");
                    // 调用更新宠物的方法
                    Scanner scanner2= new Scanner(System.in);
                    System.out.println("请输入宠物的ID：");
                    int petId = scanner2.nextInt();
                    System.out.println("请输入宠物的昵称：");
                    String nickname1 = scanner2.nextLine();
                    System.out.println("请输入宠物的类型：");
                    String type1 = scanner2.nextLine();
                    System.out.println("请输入宠物的年龄：");
                    int age1 = scanner2.nextInt();
                    System.out.println("请输入宠物的性别：");
                    String gender1 = scanner2.nextLine();
                    PetManager.updatePet(petId, nickname1, type1, age1, gender1);
                    break;
                case 3:
                    System.out.println("删除宠物");
                    // 调用删除宠物的方法
                    Scanner scanner3 = new Scanner(System.in);
                    System.out.println("请输入宠物的ID：");
                    int petId1 = scanner3.nextInt();
                    PetManager.deletePet(petId1);
                    break;
                case 4:
                    System.out.println("查看宠物");
                    // 调用查看宠物的方法
                    Scanner scanner4 = new Scanner(System.in);
                    System.out.println("请输入排序方式（年龄/类型）：");
                    String sortBy = scanner4.nextLine();
                    viewPets(sortBy);
                    break;
                case 5:
                    System.out.println("退出系统");
                    return; // 退出循环
                default:
                    System.out.println("无效的选择，请重新输入！");
            }
        }
    }

    private static void customerMenu(Scanner scanner) {
        while (true) {
            System.out.println("顾客菜单：\n1. 查看宠物\n2. 购买宠物\n3. 退出");
            System.out.print("请选择操作：");
            int choice = scanner.nextInt();
            scanner.nextLine(); // 清除缓冲区

            switch (choice) {
                case 1:

                    // 调用查看宠物的方法
                    Scanner scanner1 = new Scanner(System.in);
                    System.out.println("请输入排序方式（年龄/类型）：");
                    String sortBy = scanner1.nextLine();
                    System.out.println("排序方式：" + sortBy);
                    System.out.println("查看宠物");
                    viewPets(sortBy);
                    break;
                case 2:
                    System.out.println("购买宠物");
                    // 调用购买宠物的方法
                    Scanner scanner2 = new Scanner(System.in);
                    System.out.println("请输入宠物的ID：");
                    int petId = scanner2.nextInt();
                    System.out.println("请输入用户的ID：");
                    int userId = scanner2.nextInt();
                    PetManager.buyPet(petId, userId);
                    break;
                case 3:
                    System.out.println("退出系统");
                    return; // 退出循环
                default:
                    System.out.println("无效的选择，请重新输入！");
            }
        }
    }
}